package cn.wolfcode.crm.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.wolfcode.crm.domain.FormalCustomer;
import cn.wolfcode.crm.domain.Customer;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.mapper.CustomerMapper;
import cn.wolfcode.crm.mapper.FormalCustomerMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IFormalCustomerService;
@Service
public class FormalCustomerServiceImpl implements IFormalCustomerService{

	@Autowired
	private FormalCustomerMapper formalCustomerMapper;

	@Autowired
	private CustomerMapper customerMapper;
	
	@Override
	public void saveOrUpdate(FormalCustomer entity) {
		if (entity.getId() == null) {
			//自动录入时间
			entity.setVdate(new Date());
			//设置销售
			entity.setSellerId(1L);
			formalCustomerMapper.insert(entity);
			
			//更新Customer表，
			Customer customer = new Customer();
			customer.setId(entity.getCustomerId());
			customer.setStatus(4);
			customerMapper.update(customer);
			
		}else {
//			formalCustomerMapper.update(entity);
		}
		
	}

	@Override
	public FormalCustomer get(Long id) {
		return formalCustomerMapper.selectById(id);
	}

	@Override
	public PageInfo<FormalCustomer> list(QueryObject qo) { 
		PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
		List<FormalCustomer> list = formalCustomerMapper.selectAll(qo);
		return new PageInfo<>(list);
	}

}
